package de.fuberlin.dbs.wm.util;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import javax.servlet.ServletContext;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FreemarkerParser {
	
	private final String FREEMARKER_TEMPLATE;
	
	public FreemarkerParser(String template) {
		this.FREEMARKER_TEMPLATE = template;
	}
	
	@SuppressWarnings("rawtypes")
	public void freemarkerDo(Writer writer, Map datamodel, ServletContext context) throws IOException, TemplateException {
		Configuration cfg = new Configuration();
		cfg.setServletContextForTemplateLoading(context, "");
		Template tpl = cfg.getTemplate("templates/" + FREEMARKER_TEMPLATE);
		tpl.process(datamodel, writer);
	}
}
